var userDAL = require('../model/userDALS')
const userDALS = require('../model/userDALS')
const e = require('express')

var userController = {
    getAllContents:function(req,res){
        userDAL.getAllContents(function(err,results){
            if(err){
                res.json({code:500,msg:'数据显示错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },

    getAllContents1:function(req,res){
        userDAL.getAllContents1(function(err,results){
            if(err){
                res.json({code:500,msg:'数据显示错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },

    getAllContents2:function(req,res){
        var uId = req.query.uId
        userDAL.getAllContents2(uId,function(err,results){
            if(err){
                res.json({code:500,msg:'数据显示错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },


    sendOn:function(req,res){
        var userTitle = req.body.title
        var userContent = req.body.content
        var userId = req.body.userId
        var date = new Date().toLocaleDateString()
        var newUser = {userTitle:userTitle,userContent:userContent,date:date,userId:userId}
        userDAL.sendOn(newUser,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    addCommets:function(req,res){
        var comments = req.query.contents
        var userId = req.query.userId
        var aId = req.query.aId
        var date = new Date().toLocaleDateString()  
        var newComment = {userComment:comments,userId:userId,date:date,aId:aId}
        console.log(newComment)
        userDAL.addComments(newComment,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },

    showCommets:function(req,res){
        
        var aId = req.query.aId
        userDAL.showComments(aId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },

    updateLike:function(req,res){
        console.log('进入路由')
        var aId = req.query.aId
        var num = req.query.num
        var ups = {aId:aId,num:num}
        userDAL.updateLike(ups,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    topic:function(req,res){
        var aId = req.query.aId
        userDAL.topic(aId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    getAuthor:function(req,res){
        var aId = req.query.aId
        userDAL.getAuthor(aId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },

    focusThis:function(req,res){
        var aId = req.query.aId
        var uId = req.query.uId
        var date = new Date().toLocaleDateString()
        var user = {aId:aId,uId:uId,date:date}
        userDAL.focusThis(user,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    focusDel:function(req,res){
        var aId = req.query.aId
        var uId = req.query.uId
        
        var user = {aId:aId,uId:uId}
        userDAL.focusDel(user,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    showContent:function(req,res){
        userDALS.showContent(function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    userInfo:function(req,res){
        var userId = req.query.userId
        userDALS.userInfo(userId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    rewrite:function(req,res){
        var uId = req.query.uId
        var nickName = req.query.nickName
        var sex = req.query.sex
        var tel = req.query.tel
        var birth = req.query.birth
        var occupy = req.query.occupy
        var eMail = req.query.eMail
        var signature = req.query.signature
        var users = {uId:uId,nickName:nickName,sex:sex,tel:tel,birth:birth,occupy:occupy,eMail:eMail,signature:signature}
        // console.log(users)
        userDALS.rewrite(users,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    rePicture:function(users,res){
        var uId = users.uId
        var picture = users.uPicture
        var users = {uId:uId,picture:picture}
        userDALS.rePicture(users,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    getInfos:function(req,res){
        var uId = req.query.uId
        userDALS.getInfos(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    getArticle:function(req,res){
        var uId = req.query.uId
        userDALS.getArticle(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }  
        })
    },
    collect:function(req,res){
        var uId = req.query.uId
        var aId = req.query.aId
        var date = new Date().toLocaleDateString()
        var users = {uId:uId,aId:aId,date:date}
        userDALS.collect(users,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            } 
        })
    },
    showCollect:function(req,res){
        var uId = req.query.uId
        userDALS.showCollect(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    calLove:function(req,res){
        var uId = req.query.uId
        userDALS.calLove(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    delCollect:function(req,res){
        var uId = req.query.uId
        var aId = req.query.aId
        var users = {uId:uId,aId:aId}
        userDALS.delCollect(users,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            } 
        })
    },
    getArticleInfo:function(req,res){
        var uId = req.query.uId
        userDALS.getArticleInfo(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    addImgs:function(users,res){
        var aId = users.aId
        console.log(aId)
        var picture = users.picture
        var user = {aId:aId,picture:picture}
        userDALS.addImgs(user,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    addCommentss:function(req,res){
        var aId = req.query.aId
        var uId = req.query.uId
        var comment = req.query.content
        console.log(comment)
        var date = new Date().toLocaleDateString()
        var users = {aId:aId,uId:uId,comment:comment,date:date}
        userDALS.addCommentss(users,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    getUserInfo:function(req,res){
        var uId = req.query.uId
        userDALS.getUserInfo(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    selectConcern:function(req,res){
        var uId = req.query.uId
        userDALS.selectConcern(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    selectConcernNum:function(req,res){
        var uId = req.query.uId
        userDALS.selectConcernNum(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    selectConcernNums:function(req,res){
        var uId = req.query.uId
        userDALS.selectConcernNums(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    },
    selectConcerned:function(req,res){
        var uId = req.query.uId
        userDALS.selectConcerned(uId,function(err,results){
            if(err){
                console.log("进入路由发生错误",err.message)
                res.json({code:500,msg:'插入数据错误'})
            }else{
                res.json({code:200,msg:'ok',data:results})
            }
        })
    }
}

module.exports = userController